package util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author Tony Shen
 */
public class IdGenerator {

    private static Map idMap = new HashMap();
    private String idStr = "";

    public Long getId() {
        Date now = new Date();
        String strNow = new SimpleDateFormat("yyyyMMdd").format(now);
        Long id = (Long) idMap.get(strNow);
        if (id == null) {
            id = new Long(1);
        } else {
            id = new Long(id.longValue() + 1);
        }
        idStr = strNow + "00" + id.toString();
        idMap.put(strNow, id);
        return new Long(idStr);
    }
}
